﻿@model YueQian.ShortUrl.Admin.ViewModels.AdminCommonModel
@using YueQian.ShortUrl.Extensions
@{
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}
<script type="text/javascript" src="~/Scripts/My97DatePicker/WdatePicker.js"></script>
<script src="~/Scripts/jquery.flash.js"></script>

<div class="row-fluid">
    <h3 class="header smaller lighter green">@Html.Raw(Model.SearchKeyWord)</h3>
    <p>
        <button class="btn btn-primary" onclick="op.add()"><i class="icon-glass"></i>加分</button>
    </p>
    <div class="row-fluid" id="add" style="display: none;">
        <div class="widget-box">
            <div class="widget-header">
                <h4>积分详情</h4>
            </div>
            <div class="widget-body">
                <form class="form-horizontal" id="data-form" method="post" enctype="multipart/form-data">
                    <div class="control-group">
                        <input type="hidden" name="Id" id="Id" value="0" />
                        <input type="hidden" name="UserName" id="UserName" value="@Model.UserName" />
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="Contents">加分说明</label>
                        <div class="controls">
                            <textarea class="span8 limited" id="Contents" name="Contents" data-maxlength="120" maxlength="120"></textarea>
                        </div>
                    </div>
                    <div class="form-actions">
                        <button class="btn btn-info" type="submit"><i class="icon-ok"></i>提交</button>
                        &nbsp; &nbsp; &nbsp;
                        <button class="btn" type="reset" onclick="op.addcancel()"><i class="icon-undo"></i>取消</button>
                    </div>
                </form>
            </div>
        </div>
        <div class="hr"></div>
    </div>
    <div class="row-fluid">
        <div class="table-header">
        </div>
        <div class="toolbar">
            <form class="form-horizontal" id="searchForm">
                <div class="control-group">
                    <span>更新时间:</span><input type="text" name="periodtime" id="periodtime" style="width: 175px;" />
                    <button type="button" onclick="op.search();" class="btn btn-small btn-primary" style="margin-left: 10px;">搜 索</button>
                    <button type="reset" class="btn btn-small btn-inverse" style="margin-left: 20px;">重 置</button>
                </div>
            </form>
        </div>
        <table id="dataTable" class="table table-hover table-nomargin table-striped table-bordered">
            <thead>
                <tr>
                    <th style="width: 10px;">
                        <label>
                            <input type="checkbox" id="check_all" /><span class="lbl"></span>
                        </label>
                    </th>
                    <th>
                        积分类型
                    </th>
                    <th style="width: 140px;">
                        积分时间
                    </th>
                </tr>
            </thead>
            <tbody></tbody>
        </table>
    </div>
</div>
<link href="~/Content/admin/css/daterangepicker.css" rel="stylesheet" />
<script type="text/javascript" src="/Content/admin/js/moment.min.js"></script>
<script type="text/javascript" src="/Content/admin/js/daterangepicker.js"></script>
<script type="text/javascript" src="/Content/admin/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="/Content/admin/js/jquery.dataTables.bootstrap.js"></script>
<script type="text/javascript" src="/Scripts/jquery.validate.min.js"></script>
<script type="text/javascript" src="/Scripts/jquery.ajaxfileupload.js"></script>
<script type="text/javascript">
    var op = {
        add: function () {
            op.addcancel();
            $("#add").slideDown();
        },
        addcancel: function () {
            $("#Id").val("0");
            $("#ActualPrice").val("0");
            $("#AdvertiseNumber").val("");
            $("#Url").val("");
            $("#StartTime").val("");
            $("#EndTime").val("");
            $("#FilePath").val("");
            $("#AdvType").val("");
            $("#Contents").text("");
            $("#previewImg").attr({ "src": "", "display": "none" });
            $("#previewFlash").empty();

            $("#add").slideUp();
        },
        init: function () {

            $('#periodtime').daterangepicker();

            $("#data-form").validate({
                errorElement: "span",
                errorClass: "invalid",
                submitHandler: function (form) {
                    if (document.getElementById("Contents").value.length <= 0) {
                        alert("请填写加分原因");
                        return false;
                    }
                    $.post("/System/AddIntegral", $("#data-form").serialize(),
                        function (data) {
                            alert(data.msg);
                            if (data.result)
                                window.location.href = "/System/UserIntegral?u=@(Model.UserName)";
                            return false;
                        }, "Json");
                }
            });

            this.search();
        },

        search: function () {
            $("#dataTable").dataTable().fnDestroy();
            $('#dataTable').dataTable({
                "bProcessing": true,
                "bSort": false,
                "bServerSide": true,
                "iDisplayLength": 20,
                "bPaginate": true,
                "aoColumns": [
                    { "mDataProp": "CheckBox" },
                    { "mDataProp": "Title" },
                    { "mDataProp": "CreationDate" }
                ],
                "sAjaxSource": "/System/UserIntegral?u=@(Model.UserName)&cach=" + Math.random(),
                "sServerMethod": "POST",
                "fnServerParams": function (aoData) {
                    aoData.push({
                        "name": "StartTime",
                        "value": $("#periodtime").val().split('-')[0] || "@(DateTime.MinValue.ToString())"
                    }),
                    aoData.push({
                        "name": "EndTime",
                        "value": $("#periodtime").val().split('-')[1] || "@(DateTime.Now.ToString())"
                    })
                },
                "pagingType": "full_numbers",
                "bFilter": false,
                "sDom": 'frtip'
            });
        }
    }

    $(function () { op.init(); })
</script>
